﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace OpenRPOSBackOffice
{
    public partial class EditMenuItemDialog : ChildWindow
    {

        public EditMenuItemDialog()
        {
            InitializeComponent();
        }

        private async void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (Globals.db.MenuItemRecords.Count() > 0)
            {
                Globals.db.MenuItemRecords[Globals.menuItems.cmbMenuItems.SelectedIndex].col_FullName = tbMenuItemName.Text.Trim();
                Globals.db.MenuItemRecords[Globals.menuItems.cmbMenuItems.SelectedIndex].bFilterFullName = true;
                await Globals.db.UpdateMenuItemObject(Globals.db.MenuItemRecords[Globals.menuItems.cmbMenuItems.SelectedIndex]);
            }
            // Re-init the display
            Globals.menuItems.initMenuItems(true);
            this.DialogResult = true;
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void tbMenuItemName_KeyDown(object sender, KeyEventArgs e)
        {
            // Call the OK button handlers if "Enter" is pressed
            if (e.Key == Key.Enter)
                btnOK_Click(sender, e);
        }

    }
}

